import { useAttrs, watch } from "vue";

export function pageTitle(name: string) {
    const attrs = useAttrs();
    document.title = attrs[name] as string;

    // 监听name属性
    watch(() => attrs[name], (val) => {
        document.title = val as string;
    });

}
export function backgroundImageInStyle(name: string) {
    const attrs = useAttrs();

    // 监听style属性
    watch(() => attrs.style, (val: any) => {
        document.body.style.backgroundImage = `url(${val[name]})`;
    });

    // 监听style属性中的name属性
    if (!attrs.style) return
    let style = attrs.style as any
    if (!style) return
    let url = style[name]
    if (!url) return
    document.body.style.backgroundImage = `url(${url})`;

}


export default { pageTitle, backgroundImageInStyle }